﻿Imports System.Linq
Imports System.Data
Imports System.Web
Imports log4net
Imports Equipment.DataAccess


Partial Public Class Asset
    Private Shared logger As ILog = LogManager.GetLogger(GetType(Asset))
#Region "Properties"
    Private _db As EquipmentDataContext
    Public Property DBContext As EquipmentDataContext
        Get
            Return _db
        End Get
        Set(ByVal value As EquipmentDataContext)
            _db = value
        End Set
    End Property

    Private _fieldList As List(Of AssetField)
    Public Property Fields As List(Of AssetField)
        Get
            If _fieldList Is Nothing Then

                _fieldList = New List(Of AssetField)

                For Each roleItem In (From f In Database.Instance.AssetFields Where f.AssetID = Me.AssetID)
                    _fieldList.Add(roleItem)
                Next

            End If
            Return _fieldList
        End Get
        Set(ByVal value As List(Of AssetField))
            _fieldList = value
        End Set
    End Property

    Private _requirementGroupList As Dictionary(Of Requirement, List(Of Group))
    Public Property RequirementGroups As Dictionary(Of Requirement, List(Of Group))
        Get
            If _requirementGroupList Is Nothing Then

                _requirementGroupList = New Dictionary(Of Requirement, List(Of Group))

            End If
            Return _requirementGroupList
        End Get
        Set(ByVal value As Dictionary(Of Requirement, List(Of Group)))
            _requirementGroupList = value
        End Set
    End Property

    Private _requirementReviewGroupList As Dictionary(Of Requirement, List(Of Group))
    Public Property RequirementReviewGroups As Dictionary(Of Requirement, List(Of Group))
        Get
            If _requirementReviewGroupList Is Nothing Then

                _requirementReviewGroupList = New Dictionary(Of Requirement, List(Of Group))

            End If
            Return _requirementReviewGroupList
        End Get
        Set(ByVal value As Dictionary(Of Requirement, List(Of Group)))
            _requirementReviewGroupList = value
        End Set
    End Property

    Private _requirementDatesList As Dictionary(Of Requirement, DateTime)
    Public Property RequirementDates As Dictionary(Of Requirement, DateTime)
        Get
            If _requirementDatesList Is Nothing Then

                _requirementDatesList = New Dictionary(Of Requirement, DateTime)

            End If
            Return _requirementDatesList
        End Get
        Set(ByVal value As Dictionary(Of Requirement, DateTime))
            _requirementDatesList = value
        End Set
    End Property

    Private _requirementReviewTypeList As Dictionary(Of Requirement, RequirementReviewType)
    Public Property RequirementReviewTypes As Dictionary(Of Requirement, RequirementReviewType)
        Get
            If _requirementReviewTypeList Is Nothing Then

                _requirementReviewTypeList = New Dictionary(Of Requirement, RequirementReviewType)

            End If
            Return _requirementReviewTypeList
        End Get
        Set(ByVal value As Dictionary(Of Requirement, RequirementReviewType))
            _requirementReviewTypeList = value
        End Set
    End Property


    Private _requirementList As List(Of Requirement)
    Public Property Requirements As List(Of Requirement)
        Get
            If _requirementList Is Nothing Then

                _requirementList = New List(Of Requirement)

                For Each reqItem In (From r In Database.Instance.AssetRequirements Where r.AssetID = Me.AssetID)
                    _requirementList.Add(reqItem.Requirement)
                    If Not Me.RequirementDates.ContainsKey(reqItem.Requirement) Then
                        Dim startDate As DateTime = DateTime.UtcNow
                        If reqItem.StartDate IsNot Nothing Then
                            startDate = reqItem.StartDate
                        End If
                        Me.RequirementDates.Add(reqItem.Requirement, startDate)
                    End If
                Next

            End If
            Return _requirementList
        End Get
        Set(ByVal value As List(Of Requirement))
            _requirementList = value
        End Set
    End Property

#End Region

#Region "Public Function"
    Public Shared Function RetrieveAll() As IQueryable(Of Asset)
        Dim db As EquipmentDataContext = Database.Instance
        Return db.Assets.OrderBy(Function(e) e.AssetID)
    End Function

    Public Shared Function RetrieveAllActive() As IQueryable(Of Asset)
        Return From a In Database.Instance.Assets Where a.AssetStatus.IsActive = True
    End Function

    Public Shared Function RetrieveAllBySiteIDAndBarCode(ByVal siteID As Integer, ByVal barCode As String) As IQueryable(Of Asset)
        Return From a In Database.Instance.Assets Where a.SiteDepartment IsNot Nothing AndAlso a.SiteDepartment.ParentID = siteID AndAlso a.BarcodeID = barCode
    End Function

    Public Shared Function RetrieveAllBySiteID(ByVal siteID As Integer) As IQueryable(Of Asset)
        Return From a In Database.Instance.Assets Where a.SiteDepartment IsNot Nothing AndAlso a.SiteDepartment.ParentID = siteID
    End Function

    'Public Shared Function RetrieveAllBySiteIDFor(ByVal siteID As Integer, ByVal groupIDs As List(Of Integer)) As IQueryable(Of Asset)
    '    Return From a In Database.Instance.Assets Where a.SiteDepartment IsNot Nothing AndAlso a.SiteDepartment.ParentID = siteID AndAlso groupIDs.Contains(a.UserGroupID)
    'End Function

    Public Shared Function RetrieveAllByDepartmentIDAndTypeID(ByVal departmentID As Integer, ByVal assetTypeID As Integer) As IEnumerable(Of Asset)
        Return From a In Database.Instance.Assets Where a.AssetTypeID = assetTypeID AndAlso a.SiteDepartment IsNot Nothing AndAlso a.SiteDepartment.ID = departmentID
    End Function

    Public Shared Function RetrieveAllBySiteID(ByVal siteID As Integer, ByVal assetTypeID As Integer, ByVal groupID As Integer) As IEnumerable(Of Asset)
        Return RetrieveAll(assetTypeID, groupID).Where(Function(a) a.SiteDepartment IsNot Nothing AndAlso a.SiteDepartment.ParentID = siteID)
    End Function

    Public Shared Function RetrieveAllByDepartmentID(ByVal departmentID As Integer, ByVal assetTypeID As Integer, ByVal groupID As Integer) As IEnumerable(Of Asset)
        Return RetrieveAll(assetTypeID, groupID).Where(Function(a) a.SiteDepartment IsNot Nothing AndAlso a.SiteDepartment.ID = departmentID)
    End Function

    Public Shared Function RetrieveAllByDepartmentIDFor(ByVal departmentID As Integer, ByVal groupIDs As List(Of Integer)) As IQueryable(Of Asset)
        Return From r In Database.Instance.AssetRequirements Where (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Count(Function(aID) groupIDs.Contains(aID)) > 0 Or _
                                                                    r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Count(Function(arID) groupIDs.Contains(arID)) > 0) _
                                                                        AndAlso r.Asset.SiteDepartmentID = departmentID Select r.Asset
    End Function


    Public Shared Function RetrieveAll(ByVal assetTypeID As Integer, ByVal siteID As Integer, ByVal departmentID As Integer) As IQueryable(Of Asset)
        Dim db As EquipmentDataContext = Database.Instance
        If assetTypeID > 0 AndAlso departmentID > 0 Then
            Return From a In db.Assets Where a.AssetTypeID = assetTypeID AndAlso a.SiteDepartmentID = departmentID
        ElseIf assetTypeID > 0 AndAlso siteID > 0 Then
            Return From a In db.Assets Where a.AssetTypeID = assetTypeID AndAlso a.SiteDepartment.ParentID = siteID
        ElseIf assetTypeID = 0 AndAlso departmentID > 0 Then
            Return From a In db.Assets Where a.SiteDepartmentID = departmentID
        ElseIf assetTypeID = 0 AndAlso siteID > 0 Then
            Return From a In db.Assets Where a.SiteDepartment.ParentID = siteID
        ElseIf assetTypeID > 0 Then
            Return From a In db.Assets Where a.AssetTypeID = assetTypeID
        Else
            Return RetrieveAll()
        End If
    End Function

    Public Shared Function RetrieveAll(ByVal assetTypeID As Integer, ByVal groupID As Integer) As IQueryable(Of Asset)
        Dim db As EquipmentDataContext = Database.Instance
        If assetTypeID > 0 AndAlso groupID > 0 Then
            Return From r In db.AssetRequirements Where r.Asset.AssetTypeID = assetTypeID AndAlso (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Contains(groupID) Or r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Contains(groupID)) Select r.Asset
        ElseIf assetTypeID > 0 Then
            Return From a In db.Assets Where a.AssetTypeID = assetTypeID
        ElseIf groupID > 0 Then
            Return From r In db.AssetRequirements Where (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Contains(groupID) Or r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Contains(groupID)) Select r.Asset
        Else
            Return RetrieveAll()
        End If
    End Function

#Region "Filter"

    Public Shared Function RetrieveFilteredBySiteID(ByVal siteID As Integer, ByVal assetTypeID As Integer, ByVal groupID As Integer) As IQueryable(Of Asset)
        Return From a In RetrieveAll(assetTypeID, groupID) Where a.SiteDepartment.ParentID = siteID
    End Function

    Public Shared Function RetrieveFilteredForGroups(ByVal groupIDs As List(Of Integer), ByVal assetTypeID As Integer, ByVal groupID As Integer) As IQueryable(Of Asset)
        Return From r In RetrieveAll(assetTypeID, groupID)
    End Function

#End Region

    Public Shared Function RetrieveAllForGroups(ByVal groupIDs As List(Of Integer)) As IQueryable(Of Asset)
        Return From r In Database.Instance.AssetRequirements Where (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Count(Function(aID) groupIDs.Contains(aID)) > 0 Or _
                                                                    r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Count(Function(arID) groupIDs.Contains(arID)) > 0) _
                                                                        Select r.Asset
    End Function

    Public Function HasAccessForGroups(ByVal groupIDs As List(Of Integer)) As Boolean
        Return (From r In Database.Instance.AssetRequirements Where (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Count(Function(aID) groupIDs.Contains(aID)) > 0 Or _
                                                                    r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Count(Function(arID) groupIDs.Contains(arID)) > 0) _
                                                                       AndAlso r.AssetID = Me.AssetID Select r.AssetID).Count > 0
    End Function

    Public Shared Function RetrievePage(ByVal startRowIndex As Integer, ByVal maximumRows As Integer) As IQueryable(Of Asset)
        Return RetrieveAll().Skip(startRowIndex).Take(maximumRows)
    End Function

    Public Shared Function RetrievePage(ByVal sortType As String, ByVal startRowIndex As Integer, ByVal maximumRows As Integer) As IQueryable(Of Asset)

        Dim assetQuery = RetrieveAll()

        'Sort the query
        assetQuery = GetListSort(assetQuery, sortType)

        'Use the Skip and Take methods to limit the results to the page requested
        Return assetQuery.Skip(startRowIndex).Take(maximumRows)

    End Function

    Public Shared Function GetByBarCode(ByVal barcode As String) As Asset
        Dim _dataBase As EquipmentDataContext = Database.Instance
        Dim result = From e In _dataBase.Assets Where e.BarcodeID = barcode
        Dim assetEntity As Asset = result.FirstOrDefault()

        If assetEntity IsNot Nothing Then
            If assetEntity.AssetTypeID Is Nothing Then
                assetEntity.AssetTypeID = 0
            End If
            If assetEntity.SiteDepartmentID Is Nothing Then
                assetEntity.SiteDepartmentID = 0
            End If
            assetEntity.DBContext = _dataBase
        End If

        Return assetEntity

    End Function

    Public Shared Function GetByName(ByVal name As String) As Asset
        Dim _dataBase As EquipmentDataContext = Database.Instance
        Dim result = From e In _dataBase.Assets Where e.AssetName = name
        Dim assetEntity As Asset = result.FirstOrDefault()

        If assetEntity IsNot Nothing Then
            If assetEntity.AssetTypeID Is Nothing Then
                assetEntity.AssetTypeID = 0
            End If
            If assetEntity.SiteDepartmentID Is Nothing Then
                assetEntity.SiteDepartmentID = 0
            End If
            assetEntity.DBContext = _dataBase
        End If

        Return assetEntity

    End Function


    Public Shared Function GetByPrimaryKey(ByVal ID As Integer) As Asset
        Dim _dataBase As EquipmentDataContext = Database.Instance
        Dim result = From e In _dataBase.Assets Where e.AssetID = ID
        Dim assetEntity As Asset = result.FirstOrDefault()

        If assetEntity.AssetTypeID Is Nothing Then
            assetEntity.AssetTypeID = 0
        End If
        If assetEntity.SiteDepartmentID Is Nothing Then
            assetEntity.SiteDepartmentID = 0
        End If
        assetEntity.DBContext = _dataBase
        Return assetEntity

    End Function

#Region "Search"


    Public Shared Function SearchAssetByBarCode(ByVal prefixText As String) As IQueryable(Of Asset)
        Return From e In Database.Instance.Assets Where e.BarcodeID Like String.Format("{0}*", prefixText)
    End Function

    Public Shared Function SearchAssetByBarCodeForGroups(ByVal groupIDs As List(Of Integer), ByVal prefixText As String) As IQueryable(Of Asset)
        Return From r In Database.Instance.AssetRequirements Where (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Count(Function(aID) groupIDs.Contains(aID)) > 0 Or _
                                                                    r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Count(Function(arID) groupIDs.Contains(arID)) > 0) _
                                                                      AndAlso r.Asset.BarcodeID Like String.Format("{0}*", prefixText) Select r.Asset
    End Function

    Public Shared Function SearchAssetByBarCodeForSite(ByVal siteID As Integer, ByVal prefixText As String) As IQueryable(Of Asset)
        Return From a In Database.Instance.Assets Where a.SiteDepartment.ParentID = siteID AndAlso a.BarcodeID Like String.Format("{0}*", prefixText)
    End Function


    Public Shared Function SearchAssetByName(ByVal prefixText As String) As IQueryable(Of Asset)
        Return From e In Database.Instance.Assets Where e.AssetName Like String.Format("{0}*", prefixText)
    End Function

    Public Shared Function SearchAssetByNameForSiteID(ByVal siteID As Integer, ByVal prefixText As String) As IQueryable(Of Asset)
        Return From a In Database.Instance.Assets Where a.AssetName Like String.Format("{0}*", prefixText) AndAlso a.SiteDepartment.ParentID = siteID
    End Function

    Public Shared Function SearchAssetByNameForGroups(ByVal groupIDs As List(Of Integer), ByVal prefixText As String) As IQueryable(Of Asset)
        Return From r In Database.Instance.AssetRequirements Where (r.AssetRequirementGroups.Select(Function(g) g.GroupID).Count(Function(aID) groupIDs.Contains(aID)) > 0 Or _
                                                                    r.AssetRequirementRevewGroups.Select(Function(rg) rg.GroupID).Count(Function(arID) groupIDs.Contains(arID)) > 0) _
                                                                      AndAlso r.Asset.AssetName Like String.Format("{0}*", prefixText) Select r.Asset
    End Function

#End Region

    Public Shared Sub ChangeStatus(ByVal assetID As Integer, ByVal statusID As Integer)
        Dim assetToChange = GetByPrimaryKey(assetID)
        assetToChange.AssetStatusID = statusID
        assetToChange.Save()
    End Sub

    Private Shared Function GetListSort(ByVal assetQuery As IQueryable(Of Asset), ByVal sortType As String) As IQueryable(Of Asset)
        'Determining whether to sort ascending or descending
        '(GridView appends DESC if the column is clicked on twice to indicate a descending sort)
        Dim sortDescending As Boolean = False
        If Not [String].IsNullOrEmpty(sortType) Then
            Dim values As String() = sortType.Split(" ")
            sortType = values(0)
            If values.Length > 1 Then
                sortDescending = values(1) = "DESC"
            End If
        End If

        Select Case sortType
            Case "AssetID"
                If sortDescending Then
                    assetQuery = assetQuery.OrderByDescending(Function(eq) eq.AssetID)
                Else
                    assetQuery = assetQuery.OrderBy(Function(eq) eq.AssetID)
                End If
                Exit Select
            Case "AssetName"
                If sortDescending Then
                    assetQuery = assetQuery.OrderByDescending(Function(eq) eq.AssetName).ThenBy(Function(eq) eq.AssetID)
                Else
                    assetQuery = assetQuery.OrderBy(Function(eq) eq.AssetName).ThenBy(Function(eq) eq.AssetID)
                End If
                Exit Select
            Case "AssetType"
                If sortDescending Then
                    assetQuery = assetQuery.OrderByDescending(Function(eq) eq.AssetType.Description)
                Else
                    assetQuery = assetQuery.OrderBy(Function(eq) eq.AssetType.Description)
                End If
                Exit Select
            Case "AssetModelNo"
                If sortDescending Then
                    assetQuery = assetQuery.OrderByDescending(Function(eq) eq.ModelNo)
                Else
                    assetQuery = assetQuery.OrderBy(Function(eq) eq.ModelNo)
                End If
                Exit Select
            Case "AssetSerialNo"
                If sortDescending Then
                    assetQuery = assetQuery.OrderByDescending(Function(eq) eq.SerialNo)
                Else
                    assetQuery = assetQuery.OrderBy(Function(eq) eq.SerialNo)
                End If
                Exit Select
            Case Else
                If sortDescending Then
                    assetQuery = assetQuery.OrderByDescending(Function(eq) eq.AssetName)
                Else
                    assetQuery = assetQuery.OrderBy(Function(eq) eq.AssetName)
                End If
                Exit Select
        End Select

        Return assetQuery
    End Function

    Public Shared Function RowCount(ByVal startRowIndex As Integer, ByVal maximumRows As Integer) As Integer
        Return RetrieveAll().Count()
    End Function

    Public Shared Function RowCount() As Integer
        Return RetrieveAll().Count()
    End Function

    Public Shared Sub Insert(ByVal assetToAdd As Asset)

        Dim _dataBase As EquipmentDataContext = Database.Instance

        If assetToAdd.AssetTypeID = 0 Then
            assetToAdd.AssetTypeID = New Nullable(Of Integer)
        End If
        If assetToAdd.SiteDepartmentID = 0 Then
            assetToAdd.SiteDepartmentID = New Nullable(Of Integer)
        End If
        _dataBase.Assets.InsertOnSubmit(assetToAdd)

        Try
            _dataBase.SubmitChanges()

            For Each field In assetToAdd.Fields
                field.AssetID = assetToAdd.AssetID
                _dataBase.AssetFields.InsertOnSubmit(field)
            Next
            _dataBase.SubmitChanges()
        Catch ex As Exception
            logger.Error(ex.Message + ":" + ex.StackTrace)
        End Try

    End Sub

    Public Shared Sub Delete(ByVal assetToDelete As Asset)

        Dim _dataBase As EquipmentDataContext = Database.Instance
        Dim assetQuery = From p In _dataBase.Assets
        Dim deletingAsset As Asset = assetQuery.SingleOrDefault(Function(e) e.AssetID = assetToDelete.AssetID)

        _dataBase.Assets.DeleteOnSubmit(deletingAsset)

        Try
            _dataBase.SubmitChanges()

        Catch ex As Exception
            logger.Error(ex.Message + ":" + ex.StackTrace)
        End Try

    End Sub


    Public Shared Sub Update(ByVal newAsset As Asset)
        Dim _dataBase As EquipmentDataContext = Database.Instance
        Dim assetQuery = From p In _dataBase.Assets
        Dim assetToUpdate As Asset = assetQuery.SingleOrDefault(Function(e) e.AssetID = newAsset.AssetID)

        If Not assetToUpdate Is Nothing Then

            assetToUpdate.AssetName = newAsset.AssetName
            assetToUpdate.ModelNo = newAsset.ModelNo
            assetToUpdate.SerialNo = newAsset.SerialNo

            If newAsset.AssetTypeID = 0 Then
                assetToUpdate.AssetTypeID = New Nullable(Of Integer)
            Else
                assetToUpdate.AssetTypeID = newAsset.AssetTypeID
            End If
            If newAsset.SiteDepartmentID = 0 Then
                assetToUpdate.SiteDepartmentID = New Nullable(Of Integer)
            Else
                assetToUpdate.SiteDepartmentID = newAsset.SiteDepartmentID
            End If

        End If

        Try
            _dataBase.SubmitChanges()
        Catch ex As Exception
            logger.Error(ex.Message + ":" + ex.StackTrace)
        End Try

    End Sub

    Public Sub Save()
        If Me.DBContext IsNot Nothing Then
            Dim _dataBase As EquipmentDataContext = Me.DBContext
            Dim fields = From f In _dataBase.AssetFields Where f.AssetID = Me.AssetID
            Dim requirements = From r In _dataBase.AssetRequirements Where r.AssetID = Me.AssetID

            Try

                ' Fields
                For Each field In fields
                    Dim currField As AssetField = Me.Fields.SingleOrDefault(Function(f) f.ID = field.ID)
                    If currField Is Nothing Then
                        _dataBase.AssetFields.DeleteOnSubmit(field)
                    End If
                Next
                For Each field In Me.Fields
                    Dim currField As AssetField = fields.SingleOrDefault(Function(f) f.ID = field.ID)
                    If currField Is Nothing Then
                        field.AssetID = Me.AssetID
                        _dataBase.AssetFields.InsertOnSubmit(field)
                    End If
                Next

                ' Requirements
                For Each req In requirements
                    Dim currRequirement As Requirement = Me.Requirements.SingleOrDefault(Function(r) r.ID = req.RequirementID)
                    If currRequirement Is Nothing Then
                        For Each group In req.AssetRequirementGroups
                            _dataBase.AssetRequirementGroups.DeleteOnSubmit(group)
                        Next
                        For Each group In req.AssetRequirementRevewGroups
                            _dataBase.AssetRequirementRevewGroups.DeleteOnSubmit(group)
                        Next
                        _dataBase.AssetRequirements.DeleteOnSubmit(req)
                    End If
                Next


                For Each req In Me.Requirements
                    Dim currRequirement As AssetRequirement = requirements.SingleOrDefault(Function(ar) ar.RequirementID = req.ID)
                    Dim startDate As DateTime = DateTime.UtcNow
                    Dim reviewType As RequirementReviewType = RequirementReviewType.NotRequired
                    If Me.RequirementDates.ContainsKey(req) Then
                        startDate = Me.RequirementDates(req)
                    End If
                    If Me.RequirementReviewTypes.ContainsKey(req) Then
                        reviewType = Me.RequirementReviewTypes(req)
                    End If
                    If currRequirement Is Nothing Then
                        Dim assetReq As New AssetRequirement
                        assetReq.AssetID = Me.AssetID
                        assetReq.RequirementID = req.ID
                        assetReq.StartDate = startDate
                        assetReq.ReviewType = reviewType

                        If Me.RequirementGroups.ContainsKey(req) Then
                            Dim groupList = Me.RequirementGroups(req)
                            For Each groupItem In groupList
                                Dim newAssetReqGroup = New AssetRequirementGroup
                                newAssetReqGroup.GroupID = groupItem.ID
                                newAssetReqGroup.AssetRequirement = assetReq
                            Next
                        End If

                        If Me.RequirementReviewGroups.ContainsKey(req) Then
                            Dim reviewGroupList = Me.RequirementReviewGroups(req)
                            For Each groupItem In reviewGroupList
                                Dim newAssetReqReviewGroup = New AssetRequirementRevewGroup
                                newAssetReqReviewGroup.GroupID = groupItem.ID
                                newAssetReqReviewGroup.AssetRequirement = assetReq
                            Next
                        End If

                        _dataBase.AssetRequirements.InsertOnSubmit(assetReq)
                    Else
                        Dim groupList As List(Of Group)
                        If Me.RequirementGroups.ContainsKey(req) Then
                            groupList = Me.RequirementGroups(req)
                        Else
                            groupList = New List(Of Group)
                        End If

                        Dim reviewGroupList As List(Of Group)
                        If Me.RequirementReviewGroups.ContainsKey(req) Then
                            reviewGroupList = Me.RequirementReviewGroups(req)
                        Else
                            reviewGroupList = New List(Of Group)
                        End If

                        currRequirement.Update(startDate, reviewType, groupList, reviewGroupList)
                    End If
                Next

                _dataBase.SubmitChanges()
            Catch ex As Exception
                logger.Error(ex.Message + ":" + ex.StackTrace)
            End Try
        End If

    End Sub

#End Region

End Class